/*
  ! 前途似海，来日方长。
  ! Created: 2024/12/26 10:03:38
*/
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define int long long
#define mp(x, y) make_pair(x, y)
#define eb(...) emplace_back(__VA_ARGS__)
#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)
inline void JYFILE19();

using i64 = long long;
using pii = pair<int, int>;

bool ST;
const int N = 1e6 + 10;
const int mod = 998244353;

int n, c, m1, m2;
int k[N], b[N], t[N];
int d1[N];
int d2[N];
vector<int> ns;
vector<int> a[N];
vector<int> p[N];
vector<pii> to[N];

signed main() {
  JYFILE19();
  cin >> n;
  fro(i, 1, n) {
    cin >> k[i];
    a[i].resize(k[i]);
    p[i].resize(k[i]);
    fro(j, 0, k[i] - 1) cin >> a[i][j];
    fro(j, 0, k[i] - 1) d1[++m1] = a[i][j];
    fro(j, 1, k[i] - 1) d2[++m2] = p[i][j] = a[i][j] - a[i][j - 1] + 1, assert(a[i][j] > a[i][j - 1]);
  }
  cin >> c;
  fro(i, 1, n) cin >> b[i];
  d2[++m2] = 1;
  sort(d1 + 1, d1 + m1 + 1), m1 = unique(d1 + 1, d1 + m1 + 1) - d1 - 1;
  sort(d2 + 1, d2 + m2 + 1), m2 = unique(d2 + 1, d2 + m2 + 1) - d2 - 1;
  int cr = 0, sz = 0;
  fro(i, 1, n) {
    if (k[i] == 0) continue;
    fro(j, 0, k[i] - 1) a[i][j] = lower_bound(d1 + 1, d1 + m1 + 1, a[i][j]) - d1;
    fro(j, 1, k[i] - 1) p[i][j] = lower_bound(d2 + 1, d2 + m2 + 1, p[i][j]) - d2;
    t[a[i][0]]++;
    fro(j, 1, k[i] - 1) {
      to[p[i][j]].eb(i, j);
    }
    sz++, cr += (d1[a[i].back()] + d2[m2] - 1 - d1[a[i][0]] + 1) * c;
  }
  fro(i, 1, m1) cr += t[i] * b[t[i]];
  int sm = cr;
  pre(i, m2, 1) {
    for (auto j : to[i + 1]) {
      cr -= t[a[j.x][j.y]] * b[t[a[j.x][j.y]]];
      cr += c, sz++, t[a[j.x][j.y]]++;
      cr += t[a[j.x][j.y]] * b[t[a[j.x][j.y]]];
    }
    if (i != m2) {
      cr -= sz * (d2[i + 1] - d2[i]) * c;
    }
    if (cr < sm) {
      sm = cr;
      ns.clear();
      ns.eb(d2[i]);
    } else if (cr == sm) {
      ns.eb(d2[i]);
    }
  }
  sort(ns.begin(), ns.end());
  cout << sm << " " << ns.size() << "\n";
  for (auto i : ns) cout << i << " ";
  cout << "\n";
  return 0;
}

bool ED;
inline void JYFILE19() {
  freopen("list.in", "r", stdin);
  freopen("list.out", "w", stdout);
  srand(random_device{}());
  ios::sync_with_stdio(0), cin.tie(0);
  double MIB = fabs((&ED - &ST) / 1048576.), LIM = 512;
  cerr << "MEMORY: " << MIB << endl, assert(MIB <= LIM);
}